package cn.xie.domain.strategy.model.entity;

import cn.xie.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Optional;

/**
 * @author: xiaoxie
 * create: 2025-08-05 22:32
 * @BelongsProject: bit-market
 * @BelongsPackage: cn.xie.domain.strategy.model.entity
 * description: 策略实体类
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyEntity{
    /**
     * 抽奖策略ID
     **/
    private Long strategyId;
    /**
     * 抽奖策略描述
     **/
    private String strategyDesc;
    /**
     * 规则模型，rule配置的模型同步到此表，便于使用
     **/
    private String ruleModels;

    /**
     * @description: 获取规则模型 rule_weight,rule_blacklist
     * @author: xiaoxie
     * @date: 2025/8/5 下午10:48
     * @param: []
     * @return: java.lang.String[]
     **/
    public String[] getRuleModels(){
        return Optional.ofNullable(ruleModels)
                .map(s -> s.split(Constants.SPLIT))
                .orElse(new String[0]);
    }
    /**
     * @description: 获取权重规则模型
     * @author: xiaoxie
     * @date: 2025/8/5 下午10:48
     * @param: []
     * @return: java.lang.String[]
     **/
    public String getRuleModelWeight(){
        String[] ruleModels = Optional.ofNullable(this.getRuleModels())
                .orElse(new String[0]);
        for(String ruleModel : ruleModels){
            if(Constants.StrategyRule.RULE_WEIGHT.equalsIgnoreCase(ruleModel)) {
                return ruleModel;
            }
        }
        return null;
    }

}
